package web.UI;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginUIServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
      doPost(request, response);
	 
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		  request.setCharacterEncoding("utf-8");
		  response.setCharacterEncoding("utf-8");
	      
		  String id="";
	      String password = "";
	      Cookie[] cookies = request.getCookies();
	      if(cookies!=null&&cookies.length>0)
	      {
	           for(Cookie c:cookies)
	           {
	              if(c.getName().equals("id"))
	              {
	                   id =  URLDecoder.decode(c.getValue(),"utf-8");
	                   request.setAttribute("id", id);
	              }
	              if(c.getName().equals("password"))
	              {
	                   password =  URLDecoder.decode(c.getValue(),"utf-8");
	                   request.setAttribute("password", password);
	              }
	           }
	      }
	      
		  request.getRequestDispatcher("/login.jsp").forward(request, response);
	}


}
